package com.ocom.company.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.master.EntityEcardRegCode;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.company.dao.IDaoEcardRegCode;
import com.ocom.company.service.EcardRegCodeService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class EcardRegCodeServiceImpl extends ServiceImpl<IDaoEcardRegCode, EntityEcardRegCode> implements EcardRegCodeService {


    @Autowired
    private IDaoEcardRegCode ecardRegCode;
    //查询表ecard_reg_code
    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityEcardRegCode> getRegCodeInfo(String regCode, Long comId) {
        QueryWrapper<EntityEcardRegCode> query = Wrappers.query();
        query.eq("reg_code",regCode);
        query.eq("com_id",comId);
        query.gt("end_time", new Date().getTime());
        return ecardRegCode.selectList(query);
    }


    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public EntityEcardRegCode getRegCodeInfo(String regCode) {
        QueryWrapper<EntityEcardRegCode> query = Wrappers.query();
        query.eq("reg_code",regCode);
        query.gt("end_time", new Date().getTime());
        query.last("limit 1");
        return this.getOne(query);
    }


}
